<?php

namespace app\common\services;

use app\common\model\Grade as GradeModel;
use app\common\model\GradeLog as GradeLogModel;
use app\common\model\GradeDetail as GradeDetailModel;
use think\facade\Db;

use think\facade\Cache;

class GradeLogService
{
    /**
     * 添加
     */
    public static function add($data){
        
        $log = new GradeLogModel;
        $log->allowField(true)->save($data);
        return $log->id;
    }

    /**
     * 更新
     */
    public static function edit(array $data){
        
        return GradeLogModel::where('id',$data['id'])->update($data);
    }

    // 意见反馈详情
    public static function info($id){
        
        $info = GradeLogModel::where('id',$id)->find();
        return $info;
    }
    
    /**
     * 获取记录
     *
     * @return void
     */
    public static function list(array $data,$page_info)
    {
        $list = GradeLogModel::where($data)
            ->order('id desc')
            ->paginate($page_info['num'])->toArray();
        return $list;
    }


    /**
     * 获取记录详情
     *
     * @return void
     */
    public static function detail($id){

        $grade    = GradeModel::where(['log_id' => $id])->field('id,log_id')->find();
        if(empty($grade)){
            return [];
        }

        $grade_id = $grade['id'];
        $list     = collection(GradeDetailModel::where(['grade_id' => $grade_id])->select())->toArray();
        return $list;
    }

}